﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import sqlite3
import sys     
    
class MUpgrade(object):
    def __init__ (self,config):
        self.config = config
        self.logger = logging.getLogger('MLogger.MUpgrade.MUpgrade')
        
    def upgrade(self):
    
        if self.config.release != self.config.preferences['release']:
            new_release = int(self.config.release)
            old_release = int(self.config.preferences['release'])
            
            if old_release < 2010060101:
                self.logger.debug('Upgrading to 2010060101 from %s',old_release)
                try:
                    con = sqlite3.connect(self.config.db_path)    
                    con.execute('''CREATE TABLE IF NOT EXISTS "log" 
                        ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , 
                        "siteid" INTEGER,
                        "component" VARCHAR, 
                        "info" VARCHAR, 
                        "data" VARCHAR, 
                        "date" DATETIME
                        )                    
                    ''')
                    
                    con.execute('''CREATE TABLE IF NOT EXISTS "moodle_prefs" 
                    ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , 
                    "mid" VARCHAR, "name" VARCHAR, 
                    "query" VARCHAR, 
                    "version" VARCHAR
                    )
                    ''')
                    
                    preferences = [{'query': 'registerauth', 'version': '1.9', 'name': 'registerauth', 'id': 's__registerauth'}, {'query': 'guestloginbutton', 'version': '1.9', 'name': 'guestloginbutton', 'id': 's__guestloginbutton'}, {'query': 'alternateloginurl', 'version': '1.9', 'name': 'alternateloginurl', 'id': 's__alternateloginurl'}, {'query': 'forgottenpasswordurl', 'version': '1.9', 'name': 'forgottenpasswordurl', 'id': 's__forgottenpasswordurl'}, {'query': 'auth_instructions', 'version': '1.9', 'name': 'auth_instructions', 'id': 's__auth_instructions'}, {'query': 'allowemailaddresses', 'version': '1.9', 'name': 'allowemailaddresses', 'id': 's__allowemailaddresses'}, {'query': 'denyemailaddresses', 'version': '1.9', 'name': 'denyemailaddresses', 'id': 's__denyemailaddresses'}, {'query': 'verifychangedemail', 'version': '1.9', 'name': 'verifychangedemail', 'id': 's__verifychangedemail'}, {'query': 'recaptchapublickey', 'version': '1.9', 'name': 'recaptchapublickey', 'id': 's__recaptchapublickey'}, {'query': 'recaptchaprivatekey', 'version': '1.9', 'name': 'recaptchaprivatekey', 'id': 's__recaptchaprivatekey'}, {'query': 'notloggedinroleid', 'version': '1.9', 'name': 'notloggedinroleid', 'id': 's__notloggedinroleid'}, {'query': 'guestroleid', 'version': '1.9', 'name': 'guestroleid', 'id': 's__guestroleid'}, {'query': 'defaultuserroleid', 'version': '1.9', 'name': 'defaultuserroleid', 'id': 's__defaultuserroleid'}, {'query': 'nodefaultuserrolelists', 'version': '1.9', 'name': 'nodefaultuserrolelists', 'id': 's__nodefaultuserrolelists'}, {'query': 'defaultcourseroleid', 'version': '1.9', 'name': 'defaultcourseroleid', 'id': 's__defaultcourseroleid'}, {'query': 'creatornewroleid', 'version': '1.9', 'name': 'creatornewroleid', 'id': 's__creatornewroleid'}, {'query': 'autologinguests', 'version': '1.9', 'name': 'autologinguests', 'id': 's__autologinguests'}, {'query': 'allowuserswitchrolestheycantassign', 'version': '1.9', 'name': 'allowuserswitchrolestheycantassign', 'id': 's__allowuserswitchrolestheycantassign'}, {'query': 'format', 'version': '1.9', 'name': 'moodlecourse_format', 'id': 's_moodlecourse_format'}, {'query': 'numsections', 'version': '1.9', 'name': 'moodlecourse_numsections', 'id': 's_moodlecourse_numsections'}, {'query': 'hiddensections', 'version': '1.9', 'name': 'moodlecourse_hiddensections', 'id': 's_moodlecourse_hiddensections'}, {'query': 'newsitems', 'version': '1.9', 'name': 'moodlecourse_newsitems', 'id': 's_moodlecourse_newsitems'}, {'query': 'showgrades', 'version': '1.9', 'name': 'moodlecourse_showgrades', 'id': 's_moodlecourse_showgrades'}, {'query': 'showreports', 'version': '1.9', 'name': 'moodlecourse_showreports', 'id': 's_moodlecourse_showreports'}, {'query': 'maxbytes', 'version': '1.9', 'name': 'moodlecourse_maxbytes', 'id': 's_moodlecourse_maxbytes'}, {'query': 'metacourse', 'version': '1.9', 'name': 'moodlecourse_metacourse', 'id': 's_moodlecourse_metacourse'}, {'query': 'enablecourserequests', 'version': '1.9', 'name': 'enablecourserequests', 'id': 's__enablecourserequests'}, {'query': 'defaultrequestcategory', 'version': '1.9', 'name': 'defaultrequestcategory', 'id': 's__defaultrequestcategory'}, {'query': 'backup_sche_modules', 'version': '1.9', 'name': 'backup_backup_sche_modules', 'id': 's_backup_backup_sche_modules'}, {'query': 'backup_sche_withuserdata', 'version': '1.9', 'name': 'backup_backup_sche_withuserdata', 'id': 's_backup_backup_sche_withuserdata'}, {'query': 'backup_sche_metacourse', 'version': '1.9', 'name': 'backup_backup_sche_metacourse', 'id': 's_backup_backup_sche_metacourse'}, {'query': 'backup_sche_users', 'version': '1.9', 'name': 'backup_backup_sche_users', 'id': 's_backup_backup_sche_users'}, {'query': 'backup_sche_logs', 'version': '1.9', 'name': 'backup_backup_sche_logs', 'id': 's_backup_backup_sche_logs'}, {'query': 'backup_sche_userfiles', 'version': '1.9', 'name': 'backup_backup_sche_userfiles', 'id': 's_backup_backup_sche_userfiles'}, {'query': 'backup_sche_coursefiles', 'version': '1.9', 'name': 'backup_backup_sche_coursefiles', 'id': 's_backup_backup_sche_coursefiles'}, {'query': 'backup_sche_sitefiles', 'version': '1.9', 'name': 'backup_backup_sche_sitefiles', 'id': 's_backup_backup_sche_sitefiles'}, {'query': 'backup_sche_gradebook_history', 'version': '1.9', 'name': 'backup_backup_sche_gradebook_history', 'id': 's_backup_backup_sche_gradebook_history'}, {'query': 'backup_sche_messages', 'version': '1.9', 'name': 'backup_backup_sche_messages', 'id': 's_backup_backup_sche_messages'}, {'query': 'backup_sche_blogs', 'version': '1.9', 'name': 'backup_backup_sche_blogs', 'id': 's_backup_backup_sche_blogs'}, {'query': 'backup_sche_keep', 'version': '1.9', 'name': 'backup_backup_sche_keep', 'id': 's_backup_backup_sche_keep'}, {'query': 'backup_sche_active', 'version': '1.9', 'name': 'backup_backup_sche_active', 'id': 's_backup_backup_sche_active'}, {'query': 'backup_sche_hour', 'version': '1.9', 'name': 'backup_backup_sche_hour[m]', 'id': 's_backup_backup_sche_hour[m]'}, {'query': 'backup_sche_destination', 'version': '1.9', 'name': 'backup_backup_sche_destination', 'id': 's_backup_backup_sche_destination'}, {'query': 'enableoutcomes', 'version': '1.9', 'name': 'enableoutcomes', 'id': 's__enableoutcomes'}, {'query': 'grade_profilereport', 'version': '1.9', 'name': 'grade_profilereport', 'id': 's__grade_profilereport'}, {'query': 'grade_aggregationposition', 'version': '1.9', 'name': 'grade_aggregationposition', 'id': 's__grade_aggregationposition'}, {'query': 'grade_includescalesinaggregation', 'version': '1.9', 'name': 'grade_includescalesinaggregation', 'id': 's__grade_includescalesinaggregation'}, {'query': 'grade_hiddenasdate', 'version': '1.9', 'name': 'grade_hiddenasdate', 'id': 's__grade_hiddenasdate'}, {'query': 'gradepublishing', 'version': '1.9', 'name': 'gradepublishing', 'id': 's__gradepublishing'}, {'query': 'grade_export_displaytype', 'version': '1.9', 'name': 'grade_export_displaytype', 'id': 's__grade_export_displaytype'}, {'query': 'grade_export_decimalpoints', 'version': '1.9', 'name': 'grade_export_decimalpoints', 'id': 's__grade_export_decimalpoints'}, {'query': 'grade_navmethod', 'version': '1.9', 'name': 'grade_navmethod', 'id': 's__grade_navmethod'}, {'query': 'unlimitedgrades', 'version': '1.9', 'name': 'unlimitedgrades', 'id': 's__unlimitedgrades'}, {'query': 'grade_hideforcedsettings', 'version': '1.9', 'name': 'grade_hideforcedsettings', 'id': 's__grade_hideforcedsettings'}, {'query': 'grade_aggregation', 'version': '1.9', 'name': 'grade_aggregation[adv]', 'id': 's__grade_aggregation[adv]'}, {'query': 'grade_aggregateonlygraded', 'version': '1.9', 'name': 'grade_aggregateonlygraded[adv]', 'id': 's__grade_aggregateonlygraded[adv]'}, {'query': 'grade_aggregateoutcomes', 'version': '1.9', 'name': 'grade_aggregateoutcomes[adv]', 'id': 's__grade_aggregateoutcomes[adv]'}, {'query': 'grade_aggregatesubcats', 'version': '1.9', 'name': 'grade_aggregatesubcats[adv]', 'id': 's__grade_aggregatesubcats[adv]'}, {'query': 'grade_keephigh', 'version': '1.9', 'name': 'grade_keephigh[adv]', 'id': 's__grade_keephigh[adv]'}, {'query': 'grade_droplow', 'version': '1.9', 'name': 'grade_droplow[adv]', 'id': 's__grade_droplow[adv]'}, {'query': 'grade_displaytype', 'version': '1.9', 'name': 'grade_displaytype', 'id': 's__grade_displaytype'}, {'query': 'grade_decimalpoints', 'version': '1.9', 'name': 'grade_decimalpoints', 'id': 's__grade_decimalpoints'}, {'query': 'grade_report_studentsperpage', 'version': '1.9', 'name': 'grade_report_studentsperpage', 'id': 's__grade_report_studentsperpage'}, {'query': 'grade_report_quickgrading', 'version': '1.9', 'name': 'grade_report_quickgrading', 'id': 's__grade_report_quickgrading'}, {'query': 'grade_report_showquickfeedback', 'version': '1.9', 'name': 'grade_report_showquickfeedback', 'id': 's__grade_report_showquickfeedback'}, {'query': 'grade_report_fixedstudents', 'version': '1.9', 'name': 'grade_report_fixedstudents', 'id': 's__grade_report_fixedstudents'}, {'query': 'grade_report_meanselection', 'version': '1.9', 'name': 'grade_report_meanselection', 'id': 's__grade_report_meanselection'}, {'query': 'grade_report_showcalculations', 'version': '1.9', 'name': 'grade_report_showcalculations', 'id': 's__grade_report_showcalculations'}, {'query': 'grade_report_showeyecons', 'version': '1.9', 'name': 'grade_report_showeyecons', 'id': 's__grade_report_showeyecons'}, {'query': 'grade_report_showaverages', 'version': '1.9', 'name': 'grade_report_showaverages', 'id': 's__grade_report_showaverages'}, {'query': 'grade_report_showlocks', 'version': '1.9', 'name': 'grade_report_showlocks', 'id': 's__grade_report_showlocks'}, {'query': 'grade_report_showranges', 'version': '1.9', 'name': 'grade_report_showranges', 'id': 's__grade_report_showranges'}, {'query': 'grade_report_showuserimage', 'version': '1.9', 'name': 'grade_report_showuserimage', 'id': 's__grade_report_showuserimage'}, {'query': 'grade_report_showuseridnumber', 'version': '1.9', 'name': 'grade_report_showuseridnumber', 'id': 's__grade_report_showuseridnumber'}, {'query': 'grade_report_showactivityicons', 'version': '1.9', 'name': 'grade_report_showactivityicons', 'id': 's__grade_report_showactivityicons'}, {'query': 'grade_report_shownumberofgrades', 'version': '1.9', 'name': 'grade_report_shownumberofgrades', 'id': 's__grade_report_shownumberofgrades'}, {'query': 'grade_report_averagesdisplaytype', 'version': '1.9', 'name': 'grade_report_averagesdisplaytype', 'id': 's__grade_report_averagesdisplaytype'}, {'query': 'grade_report_rangesdisplaytype', 'version': '1.9', 'name': 'grade_report_rangesdisplaytype', 'id': 's__grade_report_rangesdisplaytype'}, {'query': 'grade_report_averagesdecimalpoints', 'version': '1.9', 'name': 'grade_report_averagesdecimalpoints', 'id': 's__grade_report_averagesdecimalpoints'}, {'query': 'grade_report_rangesdecimalpoints', 'version': '1.9', 'name': 'grade_report_rangesdecimalpoints', 'id': 's__grade_report_rangesdecimalpoints'}, {'query': 'grade_report_overview_showrank', 'version': '1.9', 'name': 'grade_report_overview_showrank', 'id': 's__grade_report_overview_showrank'}, {'query': 'grade_report_overview_showtotalsifcontainhidden', 'version': '1.9', 'name': 'grade_report_overview_showtotalsifcontainhidden', 'id': 's__grade_report_overview_showtotalsifcontainhidden'}, {'query': 'grade_report_user_showrank', 'version': '1.9', 'name': 'grade_report_user_showrank', 'id': 's__grade_report_user_showrank'}, {'query': 'grade_report_user_showpercentage', 'version': '1.9', 'name': 'grade_report_user_showpercentage', 'id': 's__grade_report_user_showpercentage'}, {'query': 'grade_report_user_showhiddenitems', 'version': '1.9', 'name': 'grade_report_user_showhiddenitems', 'id': 's__grade_report_user_showhiddenitems'}, {'query': 'grade_report_user_showtotalsifcontainhidden', 'version': '1.9', 'name': 'grade_report_user_showtotalsifcontainhidden', 'id': 's__grade_report_user_showtotalsifcontainhidden'}, {'query': 'timezone', 'version': '1.9', 'name': 'timezone', 'id': 's__timezone'}, {'query': 'forcetimezone', 'version': '1.9', 'name': 'forcetimezone', 'id': 's__forcetimezone'}, {'query': 'country', 'version': '1.9', 'name': 'country', 'id': 's__country'}, {'query': 'geoipfile', 'version': '1.9', 'name': 'geoipfile', 'id': 's__geoipfile'}, {'query': 'googlemapkey', 'version': '1.9', 'name': 'googlemapkey', 'id': 's__googlemapkey'}, {'query': 'autolang', 'version': '1.9', 'name': 'autolang', 'id': 's__autolang'}, {'query': 'lang', 'version': '1.9', 'name': 'lang', 'id': 's__lang'}, {'query': 'langmenu', 'version': '1.9', 'name': 'langmenu', 'id': 's__langmenu'}, {'query': 'langlist', 'version': '1.9', 'name': 'langlist', 'id': 's__langlist'}, {'query': 'langcache', 'version': '1.9', 'name': 'langcache', 'id': 's__langcache'}, {'query': 'locale', 'version': '1.9', 'name': 'locale', 'id': 's__locale'}, {'query': 'latinexcelexport', 'version': '1.9', 'name': 'latinexcelexport', 'id': 's__latinexcelexport'}, {'query': 'data_enablerssfeeds', 'version': '1.9', 'name': 'data_enablerssfeeds', 'id': 's__data_enablerssfeeds'}, {'query': 'chat_method', 'version': '1.9', 'name': 'chat_method', 'id': 's__chat_method'}, {'query': 'chat_refresh_userlist', 'version': '1.9', 'name': 'chat_refresh_userlist', 'id': 's__chat_refresh_userlist'}, {'query': 'chat_old_ping', 'version': '1.9', 'name': 'chat_old_ping', 'id': 's__chat_old_ping'}, {'query': 'chat_refresh_room', 'version': '1.9', 'name': 'chat_refresh_room', 'id': 's__chat_refresh_room'}, {'query': 'chat_normal_updatemode', 'version': '1.9', 'name': 'chat_normal_updatemode', 'id': 's__chat_normal_updatemode'}, {'query': 'chat_serverhost', 'version': '1.9', 'name': 'chat_serverhost', 'id': 's__chat_serverhost'}, {'query': 'chat_serverip', 'version': '1.9', 'name': 'chat_serverip', 'id': 's__chat_serverip'}, {'query': 'chat_serverport', 'version': '1.9', 'name': 'chat_serverport', 'id': 's__chat_serverport'}, {'query': 'chat_servermax', 'version': '1.9', 'name': 'chat_servermax', 'id': 's__chat_servermax'}, {'query': 'forum_displaymode', 'version': '1.9', 'name': 'forum_displaymode', 'id': 's__forum_displaymode'}, {'query': 'forum_replytouser', 'version': '1.9', 'name': 'forum_replytouser', 'id': 's__forum_replytouser'}, {'query': 'forum_shortpost', 'version': '1.9', 'name': 'forum_shortpost', 'id': 's__forum_shortpost'}, {'query': 'forum_longpost', 'version': '1.9', 'name': 'forum_longpost', 'id': 's__forum_longpost'}, {'query': 'forum_manydiscussions', 'version': '1.9', 'name': 'forum_manydiscussions', 'id': 's__forum_manydiscussions'}, {'query': 'forum_maxbytes', 'version': '1.9', 'name': 'forum_maxbytes', 'id': 's__forum_maxbytes'}, {'query': 'forum_trackreadposts', 'version': '1.9', 'name': 'forum_trackreadposts', 'id': 's__forum_trackreadposts'}, {'query': 'forum_oldpostdays', 'version': '1.9', 'name': 'forum_oldpostdays', 'id': 's__forum_oldpostdays'}, {'query': 'forum_usermarksread', 'version': '1.9', 'name': 'forum_usermarksread', 'id': 's__forum_usermarksread'}, {'query': 'forum_cleanreadtime', 'version': '1.9', 'name': 'forum_cleanreadtime', 'id': 's__forum_cleanreadtime'}, {'query': 'forum_enablerssfeeds', 'version': '1.9', 'name': 'forum_enablerssfeeds', 'id': 's__forum_enablerssfeeds'}, {'query': 'forum_enabletimedposts', 'version': '1.9', 'name': 'forum_enabletimedposts', 'id': 's__forum_enabletimedposts'}, {'query': 'forum_logblocked', 'version': '1.9', 'name': 'forum_logblocked', 'id': 's__forum_logblocked'}, {'query': 'forum_ajaxrating', 'version': '1.9', 'name': 'forum_ajaxrating', 'id': 's__forum_ajaxrating'}, {'query': 'glossary_entbypage', 'version': '1.9', 'name': 'glossary_entbypage', 'id': 's__glossary_entbypage'}, {'query': 'glossary_dupentries', 'version': '1.9', 'name': 'glossary_dupentries', 'id': 's__glossary_dupentries'}, {'query': 'glossary_allowcomments', 'version': '1.9', 'name': 'glossary_allowcomments', 'id': 's__glossary_allowcomments'}, {'query': 'glossary_linkbydefault', 'version': '1.9', 'name': 'glossary_linkbydefault', 'id': 's__glossary_linkbydefault'}, {'query': 'glossary_defaultapproval', 'version': '1.9', 'name': 'glossary_defaultapproval', 'id': 's__glossary_defaultapproval'}, {'query': 'glossary_enablerssfeeds', 'version': '1.9', 'name': 'glossary_enablerssfeeds', 'id': 's__glossary_enablerssfeeds'}, {'query': 'glossary_linkentries', 'version': '1.9', 'name': 'glossary_linkentries', 'id': 's__glossary_linkentries'}, {'query': 'glossary_casesensitive', 'version': '1.9', 'name': 'glossary_casesensitive', 'id': 's__glossary_casesensitive'}, {'query': 'glossary_fullmatch', 'version': '1.9', 'name': 'glossary_fullmatch', 'id': 's__glossary_fullmatch'}, {'query': 'resource_framesize', 'version': '1.9', 'name': 'resource_framesize', 'id': 's__resource_framesize'}, {'query': 'resource_websearch', 'version': '1.9', 'name': 'resource_websearch', 'id': 's__resource_websearch'}, {'query': 'resource_defaulturl', 'version': '1.9', 'name': 'resource_defaulturl', 'id': 's__resource_defaulturl'}, {'query': 'resource_secretphrase', 'version': '1.9', 'name': 'resource_secretphrase', 'id': 's__resource_secretphrase'}, {'query': 'resource_allowlocalfiles', 'version': '1.9', 'name': 'resource_allowlocalfiles', 'id': 's__resource_allowlocalfiles'}, {'query': 'resource_popup', 'version': '1.9', 'name': 'resource_popup', 'id': 's__resource_popup'}, {'query': 'resource_popupresizable', 'version': '1.9', 'name': 'resource_popupresizable', 'id': 's__resource_popupresizable'}, {'query': 'resource_popupscrollbars', 'version': '1.9', 'name': 'resource_popupscrollbars', 'id': 's__resource_popupscrollbars'}, {'query': 'resource_popupdirectories', 'version': '1.9', 'name': 'resource_popupdirectories', 'id': 's__resource_popupdirectories'}, {'query': 'resource_popuplocation', 'version': '1.9', 'name': 'resource_popuplocation', 'id': 's__resource_popuplocation'}, {'query': 'resource_popupmenubar', 'version': '1.9', 'name': 'resource_popupmenubar', 'id': 's__resource_popupmenubar'}, {'query': 'resource_popuptoolbar', 'version': '1.9', 'name': 'resource_popuptoolbar', 'id': 's__resource_popuptoolbar'}, {'query': 'resource_popupstatus', 'version': '1.9', 'name': 'resource_popupstatus', 'id': 's__resource_popupstatus'}, {'query': 'resource_popupwidth', 'version': '1.9', 'name': 'resource_popupwidth', 'id': 's__resource_popupwidth'}, {'query': 'resource_popupheight', 'version': '1.9', 'name': 'resource_popupheight', 'id': 's__resource_popupheight'}, {'query': 'resource_autofilerename', 'version': '1.9', 'name': 'resource_autofilerename', 'id': 's__resource_autofilerename'}, {'query': 'resource_blockdeletingfile', 'version': '1.9', 'name': 'resource_blockdeletingfile', 'id': 's__resource_blockdeletingfile'}, {'query': 'scorm_grademethod', 'version': '1.9', 'name': 'scorm_grademethod', 'id': 's__scorm_grademethod'}, {'query': 'scorm_maxgrade', 'version': '1.9', 'name': 'scorm_maxgrade', 'id': 's__scorm_maxgrade'}, {'query': 'scorm_maxattempts', 'version': '1.9', 'name': 'scorm_maxattempts', 'id': 's__scorm_maxattempts'}, {'query': 'scorm_whatgrade', 'version': '1.9', 'name': 'scorm_whatgrade', 'id': 's__scorm_whatgrade'}, {'query': 'scorm_framewidth', 'version': '1.9', 'name': 'scorm_framewidth', 'id': 's__scorm_framewidth'}, {'query': 'scorm_frameheight', 'version': '1.9', 'name': 'scorm_frameheight', 'id': 's__scorm_frameheight'}, {'query': 'scorm_popup', 'version': '1.9', 'name': 'scorm_popup', 'id': 's__scorm_popup'}, {'query': 'scorm_resizable', 'version': '1.9', 'name': 'scorm_resizable', 'id': 's__scorm_resizable'}, {'query': 'scorm_scrollbars', 'version': '1.9', 'name': 'scorm_scrollbars', 'id': 's__scorm_scrollbars'}, {'query': 'scorm_directories', 'version': '1.9', 'name': 'scorm_directories', 'id': 's__scorm_directories'}, {'query': 'scorm_location', 'version': '1.9', 'name': 'scorm_location', 'id': 's__scorm_location'}, {'query': 'scorm_menubar', 'version': '1.9', 'name': 'scorm_menubar', 'id': 's__scorm_menubar'}, {'query': 'scorm_toolbar', 'version': '1.9', 'name': 'scorm_toolbar', 'id': 's__scorm_toolbar'}, {'query': 'scorm_status', 'version': '1.9', 'name': 'scorm_status', 'id': 's__scorm_status'}, {'query': 'scorm_skipview', 'version': '1.9', 'name': 'scorm_skipview', 'id': 's__scorm_skipview'}, {'query': 'scorm_hidebrowse', 'version': '1.9', 'name': 'scorm_hidebrowse', 'id': 's__scorm_hidebrowse'}, {'query': 'scorm_hidetoc', 'version': '1.9', 'name': 'scorm_hidetoc', 'id': 's__scorm_hidetoc'}, {'query': 'scorm_hidenav', 'version': '1.9', 'name': 'scorm_hidenav', 'id': 's__scorm_hidenav'}, {'query': 'scorm_auto', 'version': '1.9', 'name': 'scorm_auto', 'id': 's__scorm_auto'}, {'query': 'scorm_updatefreq', 'version': '1.9', 'name': 'scorm_updatefreq', 'id': 's__scorm_updatefreq'}, {'query': 'assignment_maxbytes', 'version': '1.9', 'name': 'assignment_maxbytes', 'id': 's__assignment_maxbytes'}, {'query': 'assignment_itemstocount', 'version': '1.9', 'name': 'assignment_itemstocount', 'id': 's__assignment_itemstocount'}, {'query': 'assignment_showrecentsubmissions', 'version': '1.9', 'name': 'assignment_showrecentsubmissions', 'id': 's__assignment_showrecentsubmissions'}, {'query': 'block_rss_client_num_entries', 'version': '1.9', 'name': 'block_rsclient_num_entries', 'id': 's__block_rss_client_num_entries'}, {'query': 'block_rss_client_timeout', 'version': '1.9', 'name': 'block_rsclient_timeout', 'id': 's__block_rss_client_timeout'}, {'query': 'block_rss_client_submitters', 'version': '1.9', 'name': 'block_rsclient_submitters', 'id': 's__block_rss_client_submitters'}, {'query': 'block_course_list_adminview', 'version': '1.9', 'name': 'block_course_list_adminview', 'id': 's__block_course_list_adminview'}, {'query': 'block_course_list_hideallcourseslink', 'version': '1.9', 'name': 'block_course_list_hideallcourseslink', 'id': 's__block_course_list_hideallcourseslink'}, {'query': 'numsections1', 'version': '1.9', 'name': 'blocks/section_linknumsections1', 'id': 's_blocks/section_links_numsections1'}, {'query': 'incby1', 'version': '1.9', 'name': 'blocks/section_linkincby1', 'id': 's_blocks/section_links_incby1'}, {'query': 'numsections2', 'version': '1.9', 'name': 'blocks/section_linknumsections2', 'id': 's_blocks/section_links_numsections2'}, {'query': 'incby2', 'version': '1.9', 'name': 'blocks/section_linkincby2', 'id': 's_blocks/section_links_incby2'}, {'query': 'block_online_users_timetosee', 'version': '1.9', 'name': 'block_online_usertimetosee', 'id': 's__block_online_users_timetosee'}, {'query': 'cachetext', 'version': '1.9', 'name': 'cachetext', 'id': 's__cachetext'}, {'query': 'filteruploadedfiles', 'version': '1.9', 'name': 'filteruploadedfiles', 'id': 's__filteruploadedfiles'}, {'query': 'filtermatchoneperpage', 'version': '1.9', 'name': 'filtermatchoneperpage', 'id': 's__filtermatchoneperpage'}, {'query': 'filtermatchonepertext', 'version': '1.9', 'name': 'filtermatchonepertext', 'id': 's__filtermatchonepertext'}, {'query': 'filterall', 'version': '1.9', 'name': 'filterall', 'id': 's__filterall'}, {'query': 'protectusernames', 'version': '1.9', 'name': 'protectusernames', 'id': 's__protectusernames'}, {'query': 'forcelogin', 'version': '1.9', 'name': 'forcelogin', 'id': 's__forcelogin'}, {'query': 'forceloginforprofiles', 'version': '1.9', 'name': 'forceloginforprofiles', 'id': 's__forceloginforprofiles'}, {'query': 'opentogoogle', 'version': '1.9', 'name': 'opentogoogle', 'id': 's__opentogoogle'}, {'query': 'maxbytes', 'version': '1.9', 'name': 'maxbytes', 'id': 's__maxbytes'}, {'query': 'messaging', 'version': '1.9', 'name': 'messaging', 'id': 's__messaging'}, {'query': 'allowobjectembed', 'version': '1.9', 'name': 'allowobjectembed', 'id': 's__allowobjectembed'}, {'query': 'enabletrusttext', 'version': '1.9', 'name': 'enabletrusttext', 'id': 's__enabletrusttext'}, {'query': 'maxeditingtime', 'version': '1.9', 'name': 'maxeditingtime', 'id': 's__maxeditingtime'}, {'query': 'fullnamedisplay', 'version': '1.9', 'name': 'fullnamedisplay', 'id': 's__fullnamedisplay'}, {'query': 'extendedusernamechars', 'version': '1.9', 'name': 'extendedusernamechars', 'id': 's__extendedusernamechars'}, {'query': 'sitepolicy', 'version': '1.9', 'name': 'sitepolicy', 'id': 's__sitepolicy'}, {'query': 'bloglevel', 'version': '1.9', 'name': 'bloglevel', 'id': 's__bloglevel'}, {'query': 'usetags', 'version': '1.9', 'name': 'usetags', 'id': 's__usetags'}, {'query': 'keeptagnamecase', 'version': '1.9', 'name': 'keeptagnamecase', 'id': 's__keeptagnamecase'}, {'query': 'profilesforenrolledusersonly', 'version': '1.9', 'name': 'profilesforenrolledusersonly', 'id': 's__profilesforenrolledusersonly'}, {'query': 'cronclionly', 'version': '1.9', 'name': 'cronclionly', 'id': 's__cronclionly'}, {'query': 'cronremotepassword', 'version': '1.9', 'name': 'cronremotepassword', 'id': 's__cronremotepassword'}, {'query': 'passwordpolicy', 'version': '1.9', 'name': 'passwordpolicy', 'id': 's__passwordpolicy'}, {'query': 'minpasswordlength', 'version': '1.9', 'name': 'minpasswordlength', 'id': 's__minpasswordlength'}, {'query': 'minpassworddigits', 'version': '1.9', 'name': 'minpassworddigits', 'id': 's__minpassworddigits'}, {'query': 'minpasswordlower', 'version': '1.9', 'name': 'minpasswordlower', 'id': 's__minpasswordlower'}, {'query': 'minpasswordupper', 'version': '1.9', 'name': 'minpasswordupper', 'id': 's__minpasswordupper'}, {'query': 'minpasswordnonalphanum', 'version': '1.9', 'name': 'minpasswordnonalphanum', 'id': 's__minpasswordnonalphanum'}, {'query': 'disableuserimages', 'version': '1.9', 'name': 'disableuserimages', 'id': 's__disableuserimages'}, {'query': 'emailchangeconfirmation', 'version': '1.9', 'name': 'emailchangeconfirmation', 'id': 's__emailchangeconfirmation'}, {'query': 'enablenotes', 'version': '1.9', 'name': 'enablenotes', 'id': 's__enablenotes'}, {'query': 'loginhttps', 'version': '1.9', 'name': 'loginhttps', 'id': 's__loginhttps'}, {'query': 'cookiesecure', 'version': '1.9', 'name': 'cookiesecure', 'id': 's__cookiesecure'}, {'query': 'cookiehttponly', 'version': '1.9', 'name': 'cookiehttponly', 'id': 's__cookiehttponly'}, {'query': 'regenloginsession', 'version': '1.9', 'name': 'regenloginsession', 'id': 's__regenloginsession'}, {'query': 'excludeoldflashclients', 'version': '1.9', 'name': 'excludeoldflashclients', 'id': 's__excludeoldflashclients'}, {'query': 'restrictmodulesfor', 'version': '1.9', 'name': 'restrictmodulesfor', 'id': 's__restrictmodulesfor'}, {'query': 'restrictbydefault', 'version': '1.9', 'name': 'restrictbydefault', 'id': 's__restrictbydefault'}, {'query': 'displayloginfailures', 'version': '1.9', 'name': 'displayloginfailures', 'id': 's__displayloginfailures'}, {'query': 'notifyloginfailures', 'version': '1.9', 'name': 'notifyloginfailures', 'id': 's__notifyloginfailures'}, {'query': 'notifyloginthreshold', 'version': '1.9', 'name': 'notifyloginthreshold', 'id': 's__notifyloginthreshold'}, {'query': 'runclamonupload', 'version': '1.9', 'name': 'runclamonupload', 'id': 's__runclamonupload'}, {'query': 'pathtoclam', 'version': '1.9', 'name': 'pathtoclam', 'id': 's__pathtoclam'}, {'query': 'quarantinedir', 'version': '1.9', 'name': 'quarantinedir', 'id': 's__quarantinedir'}, {'query': 'clamfailureonupload', 'version': '1.9', 'name': 'clamfailureonupload', 'id': 's__clamfailureonupload'}, {'query': 'themelist', 'version': '1.9', 'name': 'themelist', 'id': 's__themelist'}, {'query': 'allowuserthemes', 'version': '1.9', 'name': 'allowuserthemes', 'id': 's__allowuserthemes'}, {'query': 'allowcoursethemes', 'version': '1.9', 'name': 'allowcoursethemes', 'id': 's__allowcoursethemes'}, {'query': 'allowcategorythemes', 'version': '1.9', 'name': 'allowcategorythemes', 'id': 's__allowcategorythemes'}, {'query': 'allowuserblockhiding', 'version': '1.9', 'name': 'allowuserblockhiding', 'id': 's__allowuserblockhiding'}, {'query': 'showblocksonmodpages', 'version': '1.9', 'name': 'showblocksonmodpages', 'id': 's__showblocksonmodpages'}, {'query': 'hideactivitytypenavlink', 'version': '1.9', 'name': 'hideactivitytypenavlink', 'id': 's__hideactivitytypenavlink'}, {'query': 'calendar_adminseesall', 'version': '1.9', 'name': 'calendar_adminseesall', 'id': 's__calendar_adminseesall'}, {'query': 'calendar_site_timeformat', 'version': '1.9', 'name': 'calendar_site_timeformat', 'id': 's__calendar_site_timeformat'}, {'query': 'calendar_startwday', 'version': '1.9', 'name': 'calendar_startwday', 'id': 's__calendar_startwday'}, {'query': 'calendar_lookahead', 'version': '1.9', 'name': 'calendar_lookahead', 'id': 's__calendar_lookahead'}, {'query': 'calendar_maxevents', 'version': '1.9', 'name': 'calendar_maxevents', 'id': 's__calendar_maxevents'}, {'query': 'enablecalendarexport', 'version': '1.9', 'name': 'enablecalendarexport', 'id': 's__enablecalendarexport'}, {'query': 'calendar_exportsalt', 'version': '1.9', 'name': 'calendar_exportsalt', 'id': 's__calendar_exportsalt'}, {'query': 'htmleditor', 'version': '1.9', 'name': 'htmleditor', 'id': 's__htmleditor'}, {'query': 'editorbackgroundcolor', 'version': '1.9', 'name': 'editorbackgroundcolor', 'id': 's__editorbackgroundcolor'}, {'query': 'editorfontfamily', 'version': '1.9', 'name': 'editorfontfamily', 'id': 's__editorfontfamily'}, {'query': 'editorfontsize', 'version': '1.9', 'name': 'editorfontsize', 'id': 's__editorfontsize'}, {'query': 'editorfontlist', 'version': '1.9', 'name': 'editorfontlist[v10]', 'id': 's__editorfontlist[v10]'}, {'query': 'editorkillword', 'version': '1.9', 'name': 'editorkillword', 'id': 's__editorkillword'}, {'query': 'emoticons', 'version': '1.9', 'name': 'emoticons[v29]', 'id': 's__emoticons[v29]'}, {'query': 'formatstringstriptags', 'version': '1.9', 'name': 'formatstringstriptags', 'id': 's__formatstringstriptags'}, {'query': 'docroot', 'version': '1.9', 'name': 'docroot', 'id': 's__docroot'}, {'query': 'doctonewwindow', 'version': '1.9', 'name': 'doctonewwindow', 'id': 's__doctonewwindow'}, {'query': 'mymoodleredirect', 'version': '1.9', 'name': 'mymoodleredirect', 'id': 's__mymoodleredirect'}, {'query': 'mycoursesperpage', 'version': '1.9', 'name': 'mycoursesperpage', 'id': 's__mycoursesperpage'}, {'query': 'enableajax', 'version': '1.9', 'name': 'enableajax', 'id': 's__enableajax'}, {'query': 'disablecourseajax', 'version': '1.9', 'name': 'disablecourseajax', 'id': 's__disablecourseajax'}, {'query': 'fullname', 'version': '1.9', 'name': 'fullname', 'id': 's__fullname'}, {'query': 'shortname', 'version': '1.9', 'name': 'shortname', 'id': 's__shortname'}, {'query': 'summary', 'version': '1.9', 'name': 'summary', 'id': 's__summary'}, {'query': 'frontpage', 'version': '1.9', 'name': 'frontpage[]', 'id': 's__frontpage[]'}, {'query': 'frontpageloggedin', 'version': '1.9', 'name': 'frontpageloggedin[]', 'id': 's__frontpageloggedin[]'}, {'query': 'maxcategorydepth', 'version': '1.9', 'name': 'maxcategorydepth', 'id': 's__maxcategorydepth'}, {'query': 'numsections', 'version': '1.9', 'name': 'numsections', 'id': 's__numsections'}, {'query': 'newsitems', 'version': '1.9', 'name': 'newsitems', 'id': 's__newsitems'}, {'query': 'coursesperpage', 'version': '1.9', 'name': 'coursesperpage', 'id': 's__coursesperpage'}, {'query': 'allowvisiblecoursesinhiddencategories', 'version': '1.9', 'name': 'allowvisiblecoursesinhiddencategories', 'id': 's__allowvisiblecoursesinhiddencategories'}, {'query': 'defaultfrontpageroleid', 'version': '1.9', 'name': 'defaultfrontpageroleid', 'id': 's__defaultfrontpageroleid'}, {'query': 'gdversion', 'version': '1.9', 'name': 'gdversion', 'id': 's__gdversion'}, {'query': 'zip', 'version': '1.9', 'name': 'zip', 'id': 's__zip'}, {'query': 'unzip', 'version': '1.9', 'name': 'unzip', 'id': 's__unzip'}, {'query': 'pathtodu', 'version': '1.9', 'name': 'pathtodu', 'id': 's__pathtodu'}, {'query': 'aspellpath', 'version': '1.9', 'name': 'aspellpath', 'id': 's__aspellpath'}, {'query': 'smtphosts', 'version': '1.9', 'name': 'smtphosts', 'id': 's__smtphosts'}, {'query': 'smtpuser', 'version': '1.9', 'name': 'smtpuser', 'id': 's__smtpuser'}, {'query': 'smtppass', 'version': '1.9', 'name': 'smtppass', 'id': 's__smtppass'}, {'query': 'smtpmaxbulk', 'version': '1.9', 'name': 'smtpmaxbulk', 'id': 's__smtpmaxbulk'}, {'query': 'noreplyaddress', 'version': '1.9', 'name': 'noreplyaddress', 'id': 's__noreplyaddress'}, {'query': 'digestmailtime', 'version': '1.9', 'name': 'digestmailtime', 'id': 's__digestmailtime'}, {'query': 'sitemailcharset', 'version': '1.9', 'name': 'sitemailcharset', 'id': 's__sitemailcharset'}, {'query': 'allowusermailcharset', 'version': '1.9', 'name': 'allowusermailcharset', 'id': 's__allowusermailcharset'}, {'query': 'mailnewline', 'version': '1.9', 'name': 'mailnewline', 'id': 's__mailnewline'}, {'query': 'supportname', 'version': '1.9', 'name': 'supportname', 'id': 's__supportname'}, {'query': 'supportemail', 'version': '1.9', 'name': 'supportemail', 'id': 's__supportemail'}, {'query': 'supportpage', 'version': '1.9', 'name': 'supportpage', 'id': 's__supportpage'}, {'query': 'dbsessions', 'version': '1.9', 'name': 'dbsessions', 'id': 's__dbsessions'}, {'query': 'sessiontimeout', 'version': '1.9', 'name': 'sessiontimeout', 'id': 's__sessiontimeout'}, {'query': 'sessioncookie', 'version': '1.9', 'name': 'sessioncookie', 'id': 's__sessioncookie'}, {'query': 'sessioncookiepath', 'version': '1.9', 'name': 'sessioncookiepath', 'id': 's__sessioncookiepath'}, {'query': 'sessioncookiedomain', 'version': '1.9', 'name': 'sessioncookiedomain', 'id': 's__sessioncookiedomain'}, {'query': 'enablerssfeeds', 'version': '1.9', 'name': 'enablerssfeeds', 'id': 's__enablerssfeeds'}, {'query': 'debug', 'version': '1.9', 'name': 'debug', 'id': 's__debug'}, {'query': 'debugdisplay', 'version': '1.9', 'name': 'debugdisplay', 'id': 's__debugdisplay'}, {'query': 'xmlstrictheaders', 'version': '1.9', 'name': 'xmlstrictheaders', 'id': 's__xmlstrictheaders'}, {'query': 'debugsmtp', 'version': '1.9', 'name': 'debugsmtp', 'id': 's__debugsmtp'}, {'query': 'perfdebug', 'version': '1.9', 'name': 'perfdebug', 'id': 's__perfdebug'}, {'query': 'enablestats', 'version': '1.9', 'name': 'enablestats', 'id': 's__enablestats'}, {'query': 'statsfirstrun', 'version': '1.9', 'name': 'statsfirstrun', 'id': 's__statsfirstrun'}, {'query': 'statsmaxruntime', 'version': '1.9', 'name': 'statsmaxruntime', 'id': 's__statsmaxruntime'}, {'query': 'statsruntimedays', 'version': '1.9', 'name': 'statsruntimedays', 'id': 's__statsruntimedays'}, {'query': 'statsruntimestarthour', 'version': '1.9', 'name': 'statsruntimestarthour[m]', 'id': 's__statsruntimestarthour[m]'}, {'query': 'statsuserthreshold', 'version': '1.9', 'name': 'statsuserthreshold', 'id': 's__statsuserthreshold'}, {'query': 'statscatdepth', 'version': '1.9', 'name': 'statscatdepth', 'id': 's__statscatdepth'}, {'query': 'framename', 'version': '1.9', 'name': 'framename', 'id': 's__framename'}, {'query': 'slasharguments', 'version': '1.9', 'name': 'slasharguments', 'id': 's__slasharguments'}, {'query': 'getremoteaddrconf', 'version': '1.9', 'name': 'getremoteaddrconf', 'id': 's__getremoteaddrconf'}, {'query': 'proxyhost', 'version': '1.9', 'name': 'proxyhost', 'id': 's__proxyhost'}, {'query': 'proxyport', 'version': '1.9', 'name': 'proxyport', 'id': 's__proxyport'}, {'query': 'proxytype', 'version': '1.9', 'name': 'proxytype', 'id': 's__proxytype'}, {'query': 'proxyuser', 'version': '1.9', 'name': 'proxyuser', 'id': 's__proxyuser'}, {'query': 'proxypassword', 'version': '1.9', 'name': 'proxypassword', 'id': 's__proxypassword'}, {'query': 'longtimenosee', 'version': '1.9', 'name': 'longtimenosee', 'id': 's__longtimenosee'}, {'query': 'deleteunconfirmed', 'version': '1.9', 'name': 'deleteunconfirmed', 'id': 's__deleteunconfirmed'}, {'query': 'deleteincompleteusers', 'version': '1.9', 'name': 'deleteincompleteusers', 'id': 's__deleteincompleteusers'}, {'query': 'loglifetime', 'version': '1.9', 'name': 'loglifetime', 'id': 's__loglifetime'}, {'query': 'disablegradehistory', 'version': '1.9', 'name': 'disablegradehistory', 'id': 's__disablegradehistory'}, {'query': 'gradehistorylifetime', 'version': '1.9', 'name': 'gradehistorylifetime', 'id': 's__gradehistorylifetime'}, {'query': 'extramemorylimit', 'version': '1.9', 'name': 'extramemorylimit', 'id': 's__extramemorylimit'}, {'query': 'cachetype', 'version': '1.9', 'name': 'cachetype', 'id': 's__cachetype'}, {'query': 'rcache', 'version': '1.9', 'name': 'rcache', 'id': 's__rcache'}, {'query': 'rcachettl', 'version': '1.9', 'name': 'rcachettl', 'id': 's__rcachettl'}, {'query': 'intcachemax', 'version': '1.9', 'name': 'intcachemax', 'id': 's__intcachemax'}, {'query': 'memcachedhosts', 'version': '1.9', 'name': 'memcachedhosts', 'id': 's__memcachedhosts'}, {'query': 'memcachedpconn', 'version': '1.9', 'name': 'memcachedpconn', 'id': 's__memcachedpconn'}, {'query': 'enableglobalsearch', 'version': '1.9', 'name': 'enableglobalsearch', 'id': 's__enableglobalsearch'}, {'query': 'smartpix', 'version': '1.9', 'name': 'smartpix', 'id': 's__smartpix'}, {'query': 'enablehtmlpurifier', 'version': '1.9', 'name': 'enablehtmlpurifier', 'id': 's__enablehtmlpurifier'}, {'query': 'enablegroupings', 'version': '1.9', 'name': 'enablegroupings', 'id': 's__enablegroupings'}, {'query': 'selectmanual', 'version': '1.9', 'name': 'qtype_random_selectmanual', 'id': 's_qtype_random_selectmanual'}, {'query': 'experimentalsplitrestore', 'version': '1.9', 'name': 'experimentalsplitrestore', 'id': 's__experimentalsplitrestore'}, {'query': 'enableimsccimport', 'version': '1.9', 'name': 'enableimsccimport', 'id': 's__enableimsccimport'}, {'query': 'enablesafebrowserintegration', 'version': '1.9', 'name': 'enablesafebrowserintegration', 'id': 's__enablesafebrowserintegration'}]
                    
                    for pref in preferences:
                        con.execute('insert into moodle_prefs (mid,name,query,version) values (?,?,?,"1.9")',(pref['id'],pref['name'],pref['query']))
                    
                    con.commit()
                    con.close()
                except:
                    self.logger.critical('Error upgrading to 2010060101 from %s: %s',old_release,sys.exc_info())
                    return False
                    
            self.config.preferences['release'] = self.config.release  
            self.config.preferences['version'] = self.config.version
            self.config.save_pref('release')
            self.config.save_pref('version')
            self.logger.debug('Upgrading to %s completed',self.config.release)
                
        return True



if __name__ == "__main__":
    #For testing    
    pass